Skip to content

AVRO-2079: Add ability to generate Java8 native date/time classes (new) - #309

Merged
nandorKollar merged 7 commits into
apache:masterfrom
pvorb:use-java8-time
Oct 1, 2018
Merged

AVRO-2079: Add ability to generate Java8 native date/time classes (new)#309
nandorKollar merged 7 commits into
apache:masterfrom
pvorb:use-java8-time

Conversation

@pvorb

@pvorb pvorb commented May 4, 2018

Copy link
Copy Markdown
Contributor

As there was no progress on #248 for the past few months, I went ahead and resolved the merge conflicts of that PR and also fixed the remarks from @Kuroshii.

Here's a brief overview of what I've changed:

  • Reorder imports in TestJava8TimeConversions.java
  • Directly cast epochDays to int
  • Directly cast millis to int
  • Explicitly format java8 and joda time dates in test
  • Rename DateTimeLogicalTypeType to DateTimeLogicalTypeImplementation
  • Refactor registration of conversions
  • Make DateTimeLigicalTypeImplementation field final
  • Use parent POM version in Maven plugin tests
  • Log warning message about unknown parameter values
  • Remove unused imports

I would also suggest to rename the enum value JAVA8 and all of its uses to JSR310 because that's more specific to the java.time.* APIs introduced in Java 8 (see https://jcp.org/en/jsr/detail?id=310). I can add that change if you agree.

@Kuroshii I would appreciate if you could review this PR again, so maybe we'll have JSR-310 support in the next Avro release. Thanks!

@pvorb
pvorb force-pushed the use-java8-time branch from 6b23527 to 6c3921c Compare May 4, 2018 13:44
@lukejackson

Copy link
Copy Markdown

Awesome, thanks @pvorb. I was not far off doing the same, as I am also very keen to see this feature added.

import org.joda.time.LocalTime;

public class TimeConversions {
public class JodaTimeConversions {

@lukejackson lukejackson May 8, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to rename this class, however in this comment Doug Cutting states:

The more back-compatible this is, the easier it will be to include in releases. Currently this renames an existing class, which is not back-compatible. As such, it thus could not be included in a minor, bugfix release.

I assume he is referring to this class when he says this.

this.enableDecimalLogicalType = enableDecimalLogicalType;
}

public boolean useJodaForDateTimeLogicalTypes() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to expose the enum here? the two getters are not independent, and the interface essentially exposes four possible states when there are only two.

<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
<version>1.9.0-SNAPSHOT</version>
<relativePath>../../../../../../../../../</relativePath>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relativePath should point to a specific pom.xml file, rather than a directory, here and in other pom.xml files touched by this change.

@lukejackson

Copy link
Copy Markdown

+1 on renaming to JSR310. (Note I am not an Avro committer).

@@ -163,9 +163,9 @@ public class ${this.mangle($schema.getName())}#if ($schema.isError()) extends or
#if ($this.hasLogicalTypeField($schema))
protected static final org.apache.avro.Conversions.DecimalConversion DECIMAL_CONVERSION = new org.apache.avro.Conversions.DecimalConversion();
#if ($this.useJodaForDateTimeLogicalTypes())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this needs to be refactored to use the new getDateTimeLogicalTypeImplementation() method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

@DolgopolovOleg

Copy link
Copy Markdown

Sorry guys, it's really crucial feature for us. What do you think how long will it take to approve it?
Many thanks =)

@pvorb
pvorb force-pushed the use-java8-time branch from b72e623 to c6257f2 Compare May 22, 2018 21:44
@pvorb

pvorb commented May 22, 2018

Copy link
Copy Markdown
Contributor Author

Recent changes:

  • added a commit that replaces JAVA8 by JSR310 as suggested by me earlier in this thread. If anybody from the Avro project disagrees with that change, I will remove it.

  • removed the runtime dependency on Guava's Strings class from the AbstractAvroMojo, which caused the archetype modules to fail.

  • added a new entry in the CHANGES.txt describing the feature

@pvorb
pvorb force-pushed the use-java8-time branch from c6257f2 to adf9bbd Compare May 23, 2018 09:19
@pvorb

pvorb commented May 23, 2018

Copy link
Copy Markdown
Contributor Author

@nandorKollar Just saw that you want to remove CHANGES.txt in #310, so I removed the new entry in order to prevent a merge conflict.

aukevanleeuwen and others added 6 commits May 28, 2018 14:52
- Reorder imports in TestJava8TimeConversions.java
- Directly cast epochDays to int
- Directly cast millis to int
- Explicitly format java8 and joda time dates in test
- Rename DateTimeLogicalTypeType to DateTimeLogicalTypeImplementation
- Refactor registration of conversions
- Make DateTimeLigicalTypeImplementation field final
- Use parent POM version in Maven plugin tests
- Log warning message about unknown parameter values
- Remove unused imports
- Avoid renaming class TimeConversions
- Set relativePath to pom files
- Replace boolean getters with enum getter to better reflect internal
  state
@pvorb
pvorb force-pushed the use-java8-time branch from adf9bbd to 902b647 Compare May 28, 2018 12:53
@pvorb

pvorb commented Jun 1, 2018

Copy link
Copy Markdown
Contributor Author

@nandorKollar Is there anything else I can do?

@pvorb

pvorb commented Jun 27, 2018

Copy link
Copy Markdown
Contributor Author

@cutting Can you please have a look? Is there anything that needs to be changed before merging this request? It would be nice to get some feedback given the time me and others invested into it.

@rocketraman

Copy link
Copy Markdown
Member

+1 java.time support is long overdue. Stephen Colebourne, the creator of joda-date, and contributor to java.time recommended migrating in 2014: http://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html.

@pvorb

pvorb commented Sep 1, 2018

Copy link
Copy Markdown
Contributor Author

This PR and its precursor are by far the most upvoted pull requests for this project. Probably it’s worth considering to merge it?

@malcolmrobbins

Copy link
Copy Markdown

Hi pvorb,
we're really keen to get hold of Java8 time support within AVRO, even if this means creating our own fork for a while as we're about to undertake a significant project... What would it take for me to do this ? i.e. can I pull the changes and apply this to my own fork of the code? Alternatively is there an AVRO release imminent to save me the trouble?

@malcolmrobbins

Copy link
Copy Markdown

i.e. can I get hold of vorb:use-java8-time for our "private use" until it becomes generally available

@rocketraman

Copy link
Copy Markdown
Member

@pvorb

pvorb commented Sep 13, 2018

Copy link
Copy Markdown
Contributor Author

@malcolmrobbins Feel free to do this. Don't expect an official release with this change anytime soon.

@malcolmrobbins

malcolmrobbins commented Sep 14, 2018

Copy link
Copy Markdown

Thanks for that - I took a copy of your branch and tried a mvn test install and the build failed on Apache Avro Tools with an error that indicates a dependency on avro-mapred:jar:tests could not be satisfied.
Note that building mapred worked fine but unlike the other modules it didn't build a tests jar and this seems to be the root cause of the dependency error.
The actual error was:

[ERROR] Failed to execute goal on project avro-tools: Could not resolve dependencies for project org.apache.avro:avro-tools:jar:1.9.0-SNAPSHOT: Could not find artifact org.apache.avro:avro-mapred:jar:tests:1.9.0-SNAPSHOT -> [Help 1]

Do have any pointers as to how I can overcome this? Thanks in advance.

@malcolmrobbins

Copy link
Copy Markdown

FYI I overcame this problem. To do this I simply needed to run the build.sh script in the lang/java folder rather than following the more explicit mvn instructions in the How To Contribute guide. Now I just need to figure out how to get the avro-maven-plugin to generate Java sources that use Java 8 datetime rather than Joda

@kgalieva

Copy link
Copy Markdown

@malcolmrobbins You need to add <dateTimeLogicalTypeImplementation>jsr310</dateTimeLogicalTypeImplementation> into configuration section.

@pvorb thank you! This patch works fine on our schemas!

@Fokko

Fokko commented Sep 24, 2018

Copy link
Copy Markdown
Contributor

I've ran some tests against Divolte and it looks great. Can we get this merged?

}

/**
* Creates a specific compler with the default (Joda) type for date/time related logical types.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: compler -> compiler

@nandorKollar nandorKollar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I just ask for two minor changes.

If nobody has any objection against merging this, then after waiting a couple of days for feedback I'll merge to master.

@pvorb

pvorb commented Sep 25, 2018

Copy link
Copy Markdown
Contributor Author

@nandorKollar I changed the code according to your requests. Good spot about overriding the getRecommendedSchema() methods in each conversion!

@nandorKollar
nandorKollar merged commit b814cd0 into apache:master Oct 1, 2018
@nandorKollar

Copy link
Copy Markdown
Contributor

Merged to master, thanks @aukevanleeuwen and @pvorb for working on this!

@pvorb

pvorb commented Oct 2, 2018

Copy link
Copy Markdown
Contributor Author

Thanks, @nandorKollar!

@Blackdread

Copy link
Copy Markdown

Hi, it is merged but avro maven plugin 1.8.0 still does not support that, right?
I am trying to set my avsc file but still get jodatime once generated

@nandorKollar

Copy link
Copy Markdown
Contributor

@Blackdread correct, it is not yet released. Java 8 native date/time support will be available in 1.9.0.

@Haybu

Haybu commented Apr 18, 2019

Copy link
Copy Markdown

Any rough estimation when 1.9.0 will be released with this feature?

@Fokko

Fokko commented Apr 21, 2019

Copy link
Copy Markdown
Contributor

Next week I'll cut the branch and release the RC. Please subscribe to the dev maillist so you can help test the RC 👍

StitchMl pushed a commit to StitchMl/avro that referenced this pull request Jul 13, 2026
…w) (apache#309)

AVRO-2079: Add ability to use Java 8 date/time types instead of Joda time.

Add compiler option to allow generating Java 8 date/time classes instead of Joda time. This commit adds a new optional compiler option -dateTimeLogicalTypeImpl to specify which date/time implementation to use. It could be joda or jsr310, if not specified by, then the default is joda.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.